gesturestylus: Only add histroy element if translation succeeded
authorTimm Bäder <mail@baedert.org>
Fri, 25 Dec 2020 09:07:43 +0000 (10:07 +0100)
committerTimm Bäder <mail@baedert.org>
Sun, 3 Jan 2021 10:01:28 +0000 (11:01 +0100)
Instead of always doing it and then undoing it if the translation does
not succeed.

gtk/gtkgesturestylus.c

index d6ac7e166c77195026d8fb976859fb72a32c5e5f..92d4a37226465d9a88070da14ef538db1a33148b 100644 (file)
@@ -344,24 +344,22 @@ gtk_gesture_stylus_get_backlog (GtkGestureStylus  *gesture,
   controller_widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
   for (i = 0; i < n_coords; i++)
     {
-      GdkTimeCoord *time_coord = &history[i];
+      const GdkTimeCoord *time_coord = &history[i];
       graphene_point_t p;
 
-      g_array_append_val (backlog_array, *time_coord);
-      time_coord = &g_array_index (backlog_array, GdkTimeCoord, backlog_array->len - 1);
       if (gtk_widget_compute_point (event_widget, controller_widget,
                                     &GRAPHENE_POINT_INIT (time_coord->axes[GDK_AXIS_X] - surf_x,
                                                           time_coord->axes[GDK_AXIS_Y] - surf_y),
                                     &p))
         {
-          time_coord->axes[GDK_AXIS_X] = p.x;
-          time_coord->axes[GDK_AXIS_Y] = p.y;
-        }
-      else
-        {
-          g_array_set_size (backlog_array, backlog_array->len - 1);
+          GdkTimeCoord translated_coord = *time_coord;
+
+          translated_coord.axes[GDK_AXIS_X] = p.x;
+          translated_coord.axes[GDK_AXIS_Y] = p.y;
+
+          g_array_append_val (backlog_array, translated_coord);
         }
-    }
+      }
 
   *n_elems = backlog_array->len;
   *backlog = (GdkTimeCoord *) g_array_free (backlog_array, FALSE);